<!DOCTYPE html>
<html class="x-admin-sm">

<head>
  {include file="public/head"}
</head>

<body>
  <div class="x-body">
    <form class="layui-form">
      <input type="hidden" name="gid" value="{$role.gid}">
      <div class="layui-form-item">
        <label class="layui-form-label">角色名称</label>
        <div class="layui-input-block">
          <input type="text" class="layui-input" name="title" value="{$role.title}">
        </div>
      </div>

      <div class="layui-form-itme">
        <label class="layui-form-label">权限菜单</label>
        {volist name="menus" id="vo"}
        <hr>
        <div class="layui-input-block">
          <input type="checkbox" name="menu[{$vo.mid}]" lay-skin="primary" title="{$vo.title}" {:isset($role['rights'])
            && $role['rights'] && in_array($vo.mid,$role['rights'])?'checked':''}>
          <hr>
          {volist name="vo.children" id="cvo"}
          <input type="checkbox" name="menu[{$cvo.mid}]" lay-skin="primary" title="{$cvo.title}"
            {:isset($role['rights']) && $role['rights'] && in_array($cvo.mid,$role['rights'])?'checked':''}>
          {/volist}
        </div>
        {/volist}
      </div>
    </form>
    <hr>
    <div class="layui-form-item" style="margin-top:10px;">
      <div class="layui-input-block">
        <button class="layui-btn" onclick="save()">保存</button>
      </div>
    </div>
  </div>
  <script>
    layui.use(['form', 'layer'], function () {
      $ = layui.jquery,
      form = layui.form,
      layer = layui.layer;
    });
    function save() {
      var title = $.trim($('input[name="title"]').val());
      if (title == '') {
        layer.msg('请填写角色名称', { 'icon': 2 });
        return;
      }
      $.post('/admin.php/roles/save', $('form').serialize(), function (res) {
        if (res.code > 0) {
          layer.msg(res.msg, { 'icon': 2 });
        } else {
          layer.msg(res.msg, { 'icon': 1 });
          setTimeout(function () { parent.window.location.reload(); }, 1000);
        }
      }, 'json');
    }
  </script>
</body>

</html>